package org.ljy.orderservice.controller;


import org.ljy.orderservice.constant.Constants;
import org.ljy.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @RequestMapping("/createOrder")
    public String createOrder() {
        //省略下单的具体业务代码
        //这里直接把订单消息存放到队列中即可
        int orderId = (new Random()).nextInt(100);
        rabbitTemplate.convertAndSend("", Constants.WORK_ORDER,"订单:"+orderId);
        return "下单成功";
    }

    //发送对象
    @RequestMapping("/createOrder2")
    public String createOrder2() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(new Random().nextInt(100));
        orderInfo.setName("商品name:"+orderInfo.getOrderId());
        rabbitTemplate.convertAndSend("", Constants.WORK_ORDER,orderInfo);
        return "下单成功2";
    }


}
